<?php
namespace App\Model;

class Order extends Model
{
    // 表名
    protected $table = 'orders';
    
    // 保护属性
    protected $guarded = [];
    
    protected $attributes = [
        'shop_id'       => 0,
        'daili_id'      => 0,
        'product_name'  => '',
        'product_image' => '',
        'express'       => '',
        'express_code'  => '',
        'status'        => self::STATUS_POST,
    ];
    
    // 格式
    protected $casts = [
        'product_image' => 'array',
        'data' => 'array'
    ];

    protected $dateFormat = 'U';
    
    // 状态
    const STATUS_POST = 0;
    const STATUS_EXPRESS = 1;
    
    // 用户
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }
    
    // 店铺
    public function shop()
    {
        return $this->belongsTo(Shop::class, 'shop_id');
    }
    
    // 商品
    public function product()
    {
        return $this->belongsTo(Product::class, 'product_id');
    }
    
    // 代理
    public function daili()
    {
        return $this->belongsTo(Daili::class, 'daili_id');
    }
}